package com.ux.chart
{
	import flash.display.Sprite;

	public class Pie2D
	{
		public function Pie2D()
		{
		}
		
		/**
		 * @param tx - 가운데 점 x
		 * @param ty - 가운데 점 y
		 * @param initAngle - 시작 각도
		 * @param targetAngle - 목표 각도
		 * @param radius - 반지름
		 * @param innerRadius - 가운데 뚤릴 원의반지름
		 * @param fillColor - 채우기 색상
		 * @param lineColor - 라인색상
		 * @param lineAlpha - 라인 알파
		 * @param lineThick - 라인 두께
		 * @return Sprite
		 * 
		 */		
		public static function makePie( tx:Number, ty:Number, initAngle:Number, targetAngle:Number, radius:Number, innerRadius:Number, fillColor:uint=0x000000, lineColor:uint=0x000000, lineAlpha:Number=1, lineThick:int=1 ):Sprite
		{
			var sp : Sprite = new Sprite();
			
			var _startX : Number = innerRadius*Math.cos( initAngle*2*Math.PI/360 ) + tx;
			var _startY : Number = innerRadius*Math.sin( initAngle*2*Math.PI/360 ) + ty;
			sp.graphics.moveTo( _startX, _startY );
			
			sp.graphics.lineStyle( lineThick, lineColor, lineAlpha );
			sp.graphics.beginFill( fillColor );
			
			var diffRadius : Number = radius - innerRadius;
			
			
			var _initAngle : Number = initAngle;
			var _x : Number = 0;
			var _y : Number = 0;
			var theta : Number = 0;
			var len:int = targetAngle;
			for (var i:int = initAngle; i <= len; i++) 
			{
				_initAngle += 1;
				theta = _initAngle*2*Math.PI/360;
				_x = radius * Math.cos( theta ) + tx; 
				_y = radius * Math.sin( theta ) + ty;
				
				sp.graphics.lineTo( _x, _y );
			}
			
			len = initAngle;
			for ( i=_initAngle; i >= len; i--) 
			{
				_initAngle -= 1;
				theta = _initAngle*2*Math.PI/360;
				_x = innerRadius * Math.cos( theta ) + tx; 
				_y = innerRadius * Math.sin( theta ) + ty;
				
				sp.graphics.lineTo( _x, _y );
			}
			
			
			sp.graphics.endFill();
			
			return sp;
			
		}
	}
}